<?php
// +-------------------------------------------------------------------
// | 
// +-------------------------------------------------------------------
// | Copyright (c) 2009-2016 All rights reserved.
// +-------------------------------------------------------------------
namespace Admin\Controller;

use Kcdns\Admin\Controller\CommonController;
use Think\Model;

class DataController extends CommonController
{

    const ORDER_STATE = [
        '15' => '待付款',
        '16' => '已付款',
        '17' => '已完成',
        '18' => '已结算',
    ];

    const GOODS_STATE = [
        '1' => '正常',
        '2' => '挖单待处理',
        '3' => '挖单已处理',
    ];
    
    public function packets()
    {
    	
    	$list = O('data')->getPacketsList(I('get.start_time'), I('get.end_time'));
    	if (I('get.is_load') == 1) {
    		O('data')->explodePackets($list);
    		exit();
    	}
    	$this->assign([
    			'list' => $list,
    			
    			]);
    	$this->display();
    }

    public function count()
    {
    	$list = O('data')->count(I('get.start_time'), I('get.end_time'));
    	$this->assign('company', $list);
    	$this->display();
    }

    public function getalldata(){
        $user = session('user_auth');
        $mid_where = isManager($user['group_id'], '', $user['uid']);
        $key = 'getalldata_cache121_'.$user['uid'];
        $cache = S($key);
        if($cache){
            return json_decode($cache ,true);
        }
        $today = date("Y-m-d");
        $yesterday = date("Y-m-d", strtotime(date("Y-m-d"))-86400);
        $thismonth_start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
        $thismonth_end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
        $lastmonth_start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y")));
        $lastmonth_end = date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y")));
        $where = array_merge($mid_where, ['order_time'=>['egt',$today],'validCode'=>['in','15,16,17,18']]);
        $today_input_count =  M('zs_order_pay')->where($where)->count();
        $where = array_merge($mid_where, ['order_time'=>['egt',$today],'validCode'=>['in','16,17,18']]);
        $today_order_count = M('zs_order_pay')->where($where)->count();
        $where = array_merge($mid_where, ['order_time'=>['egt',$today],'validCode'=>['in','16,17,18']]);
        $today_money = M('zs_order_pay')->where($where)->sum('estimateCosPrice');
        $where = array_merge($mid_where, ['order_time'=>['egt',$today],'validCode'=>['in','16,17,18']]);
        $today_yugu = M('zs_order_pay')->where($where)->sum('estimateFee');
        $where = array_merge($mid_where, ['order_time'=>['between',[$yesterday,$today]],'validCode'=>['in','15,16,17,18']]);
        $yestoday_order_count = M('zs_order_pay')->where($where)->count();
        $where = array_merge($mid_where,['order_time'=>['between',[$yesterday,$today]],'validCode'=>['in','16,17,18']]);
        $yestoday_yugu = M('zs_order_pay')->where($where)->sum('estimateFee');
        $where = array_merge($mid_where, ['order_time'=>['between',[$thismonth_start,$thismonth_end]],'validCode'=>['in','15,16,17,18']]);
        $thismon_input = M('zs_order_pay')->where($where)->count();
        $where = array_merge($mid_where, ['order_time'=>['between',[$thismonth_start,$thismonth_end]],'validCode'=>['in','16,17,18']]);
        $thismon_order = M('zs_order_pay')->where($where)->count();
        $where = array_merge($mid_where, ['order_time'=>['between',[$thismonth_start,$thismonth_end]],'validCode'=>['in','16,17,18']]);
        $thismon_yugu = M('zs_order_pay')->where($where)->sum('estimateFee');
        $where = array_merge($mid_where, ['order_time'=>['between',[$lastmonth_start,$lastmonth_end]],'validCode'=>['in','15,16,17,18']]);
        $lastmon_input = M('zs_order_pay')->where($where)->count();
        $where = array_merge($mid_where, ['order_time'=>['between',[$lastmonth_start,$lastmonth_end]],'validCode'=>['in','16,17,18']]);
        $lastmon_order = M('zs_order_pay')->where($where)->count();
        $where = array_merge($mid_where, ['order_time'=>['between',[$lastmonth_start,$lastmonth_end]],'validCode'=>['in','16,17,18']]);
        $lastmon_yugu = M('zs_order_pay')->where($where)->sum('estimateFee');


        $data = [
            'today_input_count'=>$today_input_count,
            'today_order_count'=>$today_order_count,
            'today_money'=>$today_money,
            'today_yugu'=>$today_yugu,
            'yestoday_order_count'=>$yestoday_order_count,
            'yestoday_yugu'=>$yestoday_yugu,
            'thismon_input'=>$thismon_input,
            'thismon_order'=>$thismon_order,
            'thismon_yugu'=>$thismon_yugu,
            'lastmon_input'=>$lastmon_input,
            'lastmon_order'=>$lastmon_order,
            'lastmon_yugu'=>$lastmon_yugu,
        ];
        S($key, json_encode($data), ['expire' => 600]);
        return $data;
    }

    public function totalGoods(){
        $user = session('user_auth');
        $mid_where = isManager($user['group_id'], '', $user['uid']);
        //待挖单
        $daiwa_count = M('zs_goods')->where(array_merge(['state'=>2], $mid_where))->count();
        //挖单已处理
        $deal_count = M('zs_goods')->where(array_merge(['state'=>3], $mid_where))->count();

        $yestoday = date('Y-m-d', strtotime('-1days'));
        $today = date('Y-m-d');
        $mingday = date('Y-m-d', time()+60*60*24 );
        //昨天过期
        $where = array_merge([
            'endDate'=>['between',[$yestoday. ' 00:00::00',$yestoday. ' 23:59:59']]
        ], $mid_where);
        $yestoday_count = M('zs_goods')->where($where)->count();
        //今天过期
        $where = array_merge([
            'endDate'=>['between',[$today. ' 00:00::00',$today. ' 23:59:59']]
        ], $mid_where);
        $today_count = M('zs_goods')->where($where)->count();
        //m明天过期
        $where = array_merge([
            'endDate'=>['between',[$mingday. ' 00:00::00',$mingday. ' 23:59:59']]
        ], $mid_where);
        $mingday_count = M('zs_goods')->where($where)->count();
        $data = [
            'daiwa_count'=>$daiwa_count?$daiwa_count:0,
            'deal_count'=>$deal_count?$deal_count:0,
            'yestoday_count'=>$yestoday_count?$yestoday_count:0,
            'today_count'=>$today_count?$today_count:0,
            'mingday_count'=>$mingday_count?$mingday_count:0,
        ];

        return $data;
    }

    public function kongzhitai(){

        import('ORG.Util.Page');// 导入分页类

        $today = date("Y-m-d");

        $data = $this->getalldata();


            $time1 = I('start_time');
            $time2 = I('end_time');

        if ($time1 && $time2) {
            $time1 = $time1 . ' 0:0:0';
            $time2 = $time2 . ' 23:59:59';
            $where2 = ['order_time'=>['between', [$time1, $time2]],'is_pay'=>1];
        }else{
            $where2 = ['order_time'=>['egt',$today],'is_pay'=>1];
        }

        $memberlist = M('member')->select();
        $paihangbang = [];
        if($memberlist){
            foreach ($memberlist as $k =>$v){

                $where21 = array_merge($where2,['mid'=>$v['uid']]);

                $yugu = M('zs_order_pay')->where($where21)->sum('pay_service_money');
                $paihangbang[$k]['username']= $v['nickname'];
                $paihangbang[$k]['money']= $yugu?:0;
                $paihangbang[$k]['jointime']= date('Y-m-d',$v['reg_time']);
            }
        }
        $paihangbang = $this->arraySort($paihangbang,'money',$sort='desc');

        $gongsibang = [];
        $actcom = M('zs_activity')->select();
        if($actcom){
            foreach ($actcom as $kk =>$vv){
                $where22 = array_merge($where2,['taobao_act_id'=>$vv['taobao_act_id']]);
                $ordermoney = M('zs_order_pay')->where($where22)->sum('price');
                $yugu_money = M('zs_order_pay')->where($where22)->sum('yugu_money');
                $todayorder_count = M('zs_order_pay')->where($where22)->count();

                $days = $this->calcTime($today,$vv['end_time']);

                $gongsibang[$kk]['activity_title'] = $vv['activity_title'];
                $gongsibang[$kk]['taobao_act_id'] = $vv['taobao_act_id'];
                $gongsibang[$kk]['start_time'] = $vv['start_time'];
                $gongsibang[$kk]['end_time'] = $vv['end_time'];
                $gongsibang[$kk]['days'] = $days;
                $gongsibang[$kk]['todayordercount'] = $todayorder_count;
                $gongsibang[$kk]['ordermoney'] = $ordermoney;
                $gongsibang[$kk]['yugu_money'] = $yugu_money;
                if($todayorder_count<=0){
                    unset($gongsibang[$kk]);
                }
            }
        }

        $this->assign('alldata',$data);
        $this->assign('gongsibang',$gongsibang);
        $this->assign('paihangbang',$paihangbang);
        $this->display();
    }

//orderlist
    public function orderlist()
    {

        import('ORG.Util.Page');// 导入分页类

        $data = $this->getalldata();
        $model = new Model();
//        $zs_order_pay = M('zs_order_pay');
        $zs_order_pay = $model->table('__ZS_ORDER_PAY__ as u');

        $today = date("Y-m-d 00:00:00", strtotime('-7days'));
        $ordersn = I('ordersn');
        $time1 = I('start_time');
        $time2 = I('end_time');
        $validCode = I('validCode');

        if ($time1 && $time2) {
            $time1 = $time1 . ' 0:0:0';
            $time2 = $time2 . ' 23:59:59';
            $where2 = ['u.order_time' => ['between', [$time1, $time2]], 'is_pay' => 1];
        } else {
            $where2 = ['u.order_time' => ['egt', $today], 'is_pay' => 1];
        }

        if ($ordersn) {
            $where2 = array_merge($where2, ['order_no' => $ordersn]);
        }

        if ($validCode == 15 || $validCode == 16 || $validCode == 17 || $validCode == 18) {
            $where2['u.validCode'] = $validCode;
        }

        if ($validCode == 30) {
            $where2['u.validCode'] = ['LT', 15];
        }

        $user = session('user_auth');
        $where2 = array_merge($where2, isManager($user['group_id'], 'u.', $user['uid']));

        $p = $this->getpage($zs_order_pay, $where2, 10);


        $ss = $zs_order_pay->field('u.*')
            ->where($where2)
            ->order('u.order_time desc')
            ->select();
        $member_list = M('member')->select();
        $member = [];
        foreach ($member_list as $k => $v) {
            $member['uid'] = $v['nickname'];
        }
        $goods = [];
        foreach ($ss as &$item) {
            $item['order_state_label'] = self::ORDER_STATE[$item['validCode']] ? self::ORDER_STATE[$item['validCode']] : '无效';
            if ($item['finish_time']) $item['finish_time'] = date('Ymd H:i', strtotime($item['finish_time']));
            if ($item['order_time']) $item['order_time'] = date('Ymd H:i', strtotime($item['order_time']));
            if ($item['pay_month']) $item['pay_month'] = date('Ymd H:i', strtotime($item['pay_month']));
            $item['nickname'] = '';
            if ($item['mid']) {
                $item['nickname'] = $member[$item['mid']];
            }
            if(!$goods[$item['skuId']]){
                $data = M('zs_goods')->field('skuId, imgUrl, materialUrl')->where(['skuId' => $item['skuId']])->find();
                $goods[$item['skuId']] = $data;
            }
            $item['materialUrl'] = $goods[$item['skuId']]['materialUrl'];
            $item['imgUrl'] = $goods[$item['skuId']]['imgUrl'];
        }
        $aa = $zs_order_pay->getLastSql();

        $this->assign('alldata', $data);
        $this->assign('start_time', $time1);
        $this->assign('end_time', $time2);
        $this->assign('list', $ss);
        $this->assign('page', $p->show());
        $this->assign('validCode', I('get.validCode') ? I('get.validCode') : 1);
        $this->display();
    }


    //分页
    public function getpage(&$m,$where,$pagesize=10){
        $m1=clone $m;//浅复制一个模型
        $count = $m->where($where)->count();//连惯操作后会对join等操作进行重置
        $m=$m1;//为保持在为定的连惯操作，浅复制一个模型
        $p=new \Think\Page($count,$pagesize);
        $p->lastSuffix=false;

	    $p->setConfig('header','<li class="rows">共<b>%TOTAL_ROW%</b>条记录&nbsp;&nbsp;第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>');
        $p->setConfig('prev','上一页');
        $p->setConfig('next','下一页');
	    $p->setConfig('last','末页');
	    $p->setConfig('first','首页');
	    $p->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');

//	    $p->parameter=I('get.');

        $m->limit($p->firstRow,$p->listRows);

        return $p;
    }



    function arraySort($array,$keys,$sort='asc') {
        $newArr = $valArr = array();
        foreach ($array as $key=>$value) {
            $valArr[$key] = $value[$keys];
        }
        ($sort == 'asc') ?  asort($valArr) : arsort($valArr);
        reset($valArr);
        foreach($valArr as $key=>$value) {
            $newArr[$key] = $array[$key];
        }
        return $newArr;
    }

    public function ranking(){

        $today = date("Y-m-d");

        $today_yugu = M('zs_order_pay')->where(['order_time'=>['egt',$today],'is_pay'=>1])->sum('pay_service_money');

        $data = [
            'today_yugu'=>$today_yugu,
        ];

        $where2 = ['order_time'=>['egt',$today],'is_pay'=>1];

        $memberlist = M('member')->select();
        $paihangbang = [];
        if($memberlist){
            foreach ($memberlist as $k =>$v){

                $where2 = array_merge($where2,['mid'=>$v['uid']]);

                $yugu = M('zs_order_pay')->where($where2)->sum('pay_service_money');
                $paihangbang[$k]['username']= $v['nickname'];
                $paihangbang[$k]['money']= $yugu?:0;
            }
        }
        $paihangbang = $this->arraySort($paihangbang,'money',$sort='desc');

        $this->assign('alldata',$data);
        $this->assign('paihangbang',$paihangbang);
        $this->display();
    }

    public function rankingnew(){

        $today = date("Y-m-d");

        $today_yugu = M('zs_order_pay')->where(['order_time'=>['egt',$today],'is_pay'=>1])->sum('pay_service_money');

        $data = [
            'today_yugu'=>$today_yugu,
        ];

        $where2 = ['order_time'=>['egt',$today],'is_pay'=>1];

        $memberlist = M('member')->select();
        $paihangbang = [];
        if($memberlist){
            foreach ($memberlist as $k =>$v){

                $where2 = array_merge($where2,['mid'=>$v['uid']]);

                $yugu = M('zs_order_pay')->where($where2)->sum('pay_service_money');
                $paihangbang[$k]['username']= $v['nickname'];
                $paihangbang[$k]['money']= $yugu?:0;
            }
        }
        $paihangbang = $this->arraySort($paihangbang,'money',$sort='desc');

        $this->assign('alldata',$data);
        $this->assign('paihangbang',$paihangbang);
        $this->display();
    }

    public function getRankingData(){
        $today = date("Y-m-d");

        $where2 = ['order_time'=>['egt',$today],'validCode'=>['in','16,17,18']];
        $sum = M('zs_order_pay')->where($where2)->sum('estimateFee');


        $group = M('auth_group')->field('*')->where(['is_zs' => 1])->select();
        $gid_arr = array_column($group, 'id');
        $group_access = M('auth_group_access')->where(['group_id' => ['in', $gid_arr]])->select();
        $uid_arr = array_column($group_access, 'uid');
        $where = ['uid' => ['in', $uid_arr]];
        $memberlist =  M('member')->field('*')->where($where)->select();

       /* $group_access = M('auth_group_access')->where(['group_id' => 23])->select();
        $uid_arr = array_column($group_access, 'uid');
        $memberlist = M('member')->where(['uid' => ['in', $uid_arr]])->select();*/

        $paihangbang = [];

        if($memberlist){
            foreach ($memberlist as $k =>$v){
                $where2 = array_merge($where2, ['mid' => $v['uid']]);
                $yugu = M('zs_order_pay')->where($where2)->sum('estimateFee');
                $paihangbang[$k]['nickname']= $v['nickname'];
                $paihangbang[$k]['estimateServiceFee']= $yugu?:0;
            }
        }
//        ksort($paihangbang, 'estimateServiceFee');
        $last_names = array_column($paihangbang,'estimateServiceFee');
        array_multisort($last_names,SORT_DESC,$paihangbang);
        $i = 1;


        foreach($paihangbang as &$item){
            $item['rank'] =$i;
            $i++;
            $item['prent'] =($item['estimateServiceFee']/$sum)*100;
            if($item['prent']>18) $item['prent']= 16;
        }
        $this->ajaxReturn([
            'list1' =>$paihangbang,
            'list2' =>$paihangbang,
            'total' => count($paihangbang),
            'totalfee' => $sum,
        ]);
    }

    function calcTime($fromTime, $toTime){

        //转时间戳
        $fromTime = strtotime($fromTime);
        $toTime = strtotime($toTime);
        //计算时间差
        $newTime = $toTime - $fromTime;
        if($newTime<0){
            $data = "<span style='color: red'>".round($newTime / 86400) . '天'."</span>";
        }else{
            $data = "<span>".round($newTime / 86400) . '天'."</span>";
        }
        return $data;

    }

    public function sellerlist()
    {

        import('ORG.Util.Page');// 导入分页类

        $data = $this->getalldata();
        $model = new Model();
//        $zs_order_pay = M('zs_order_pay');
        $zs_order_pay = $model->table('__ZS_ORDER_PAY__ as u');

        $today = date("Y-m-d");
        $ordersn = I('ordersn');
        $time1 = I('start_time');
        $time2 = I('end_time');
        $validCode = I('validCode');
        $sellerCode = I('sellerCode');

        if ($time1 && $time2) {
            $where2 = ['u.order_time'=>['between', [$time1, $time2]],'is_pay'=>1];
        }else{
            $time1 = date('Y-m-d', strtotime("-3days"));
            $time2 = date('Y-m-d' ,strtotime('+1days'));
            $where2 = ['u.order_time'=>['between', [$time1, $time2]],'is_pay'=>1];
//            $where2 = ['u.order_time'=>['egt',$today],'is_pay'=>1];
        }

        if($ordersn){
            $where2 = array_merge($where2,['u.order_no'=>$ordersn]);
        }
        if($sellerCode){
            $where2 = array_merge($where2,['g.shopId'=>$sellerCode]);
        }

        if($validCode == 15 || $validCode == 16 || $validCode == 17 || $validCode == 18){
            $where2['u.validCode'] = $validCode;
        }



        if($validCode == 30){
            $where2['u.validCode'] = ['LT', 15];
        }

        $user = session('user_auth');
        $where2 = array_merge($where2, isManager($user['group_id'], 'u.', $user['uid']));

        $p = $this->getpage( $zs_order_pay ,$where2,10);



        $ss =  $zs_order_pay ->field('u.*,g.*')
//            ->alias('u')
            ->join('__ZS_GOODS__ g on g.skuId = u.skuId')
//            ->join('__SELLER__ s on s.shopId = g.shopId')
            ->where($where2)
            ->order('u.order_time desc')
            ->select();
        foreach($ss as &$item){
            $item['order_state_label'] = self::ORDER_STATE[$item['validCode']]?self::ORDER_STATE[$item['validCode']]:'无效';
            if($item['finish_time']) $item['finish_time'] = date('Ymd H:i', strtotime($item['finish_time']));
            if($item['order_time']) $item['order_time'] = date('Ymd H:i', strtotime($item['order_time']));
            if($item['pay_month'])  $item['pay_month'] = date('Ymd H:i', strtotime($item['pay_month']));
        }

//        $aa = $zs_order_pay->getLastSql();


        $gongsibang = [];
        $where = isManager($user['group_id'], '', $user['uid']);
        $actcom = M('zs_seller')->where($where)->select();
        if($actcom){
            foreach ($actcom as $kk =>$vv){
                $activity = M('zs_activity')->where(['taobao_act_id'=>$vv['taobao_act_id']])->find();
                $where22 = array_merge($where2,['u.taobao_act_id'=>$vv['taobao_act_id'],'u.shopId' => $vv['shopId']]);
                $ordermoney = M('zs_order_pay as u')->where($where22)->sum('estimateCosPrice');
                $yugu_money = M('zs_order_pay as u')->where($where22)->sum('estimateFee');
                $todayorder_count = M('zs_order_pay as u')->where($where22)->count();

                $days = $this->calcTime($today,$activity['end_time']);

                $tmp['seller_title'] = $vv['seller_title'];
                $tmp['shopId'] = $vv['shopId'];
                $tmp['taobao_act_id'] = $vv['taobao_act_id'];
                $tmp['start_time'] = $activity['start_time'];
                $tmp['end_time'] = $activity['end_time'];
                $tmp['days'] = $days;
                $tmp['todayordercount'] = $todayorder_count;
                $tmp['ordermoney'] = $ordermoney;
                $tmp['yugu_money'] = $yugu_money;
                $gongsibang[] = $tmp;
                /*if($todayorder_count<=0){

                }*/
            }
        }
//        var_dump($gongsibang);exit();

        $this->assign('alldata',$data);
        $this->assign('list', $ss);
        $this->assign('page',$p->show());
        $this->assign('validCode', I('get.validCode')?I('get.validCode'):1);
        $this->assign('gongsibang',$gongsibang);
        $this->assign('sellerCode',$sellerCode);
        $this->assign('start_time',$time1);
        $this->assign('end_time',$time2);
        $this->display();
    }


    public function goodslist()
    {

        import('ORG.Util.Page');// 导入分页类

        $data = $this->totalGoods();
        $model = new Model();
//        $zs_order_pay = M('zs_order_pay');
        $goods = $model->table('__ZS_GOODS__ as u');

        $today = date("Y-m-d");
        $taobao_act_id = I('taobao_act_id');
        $time1 = I('start_time');
        $time2 = I('end_time');
        $state = I('state');
        $where2 = [];
        if ($time1 && $time2) {
            $where2 = ['u.endDate'=>['between', [$time1, $time2]]];
        }/*else{
            $where2 = ['u.endDate'=>['egt',$today]];
        }*/

        if($taobao_act_id){
            $where2 = array_merge($where2,['g.taobao_act_id'=>$taobao_act_id]);
        }

        if($state){
            $where2['u.state'] = $state;
        }

        $user = session('user_auth');
        $where2 = array_merge($where2, isManager($user['group_id'], 'u.', $user['uid']));

        $p = $this->getpage( $goods ,$where2,10);



        $ss =  $goods ->field('u.*,g.taobao_act_id,g.seller_nickname, g.seller_nickname')
//            ->alias('u')
            ->join('__ZS_SELLER__ g on g.shopId = u.vid', 'LEFT')
            ->where($where2)
            ->order('u.id desc')
            ->select();
        foreach($ss as &$item){
            $item['state_label'] = self::GOODS_STATE[$item['state']]?self::GOODS_STATE[$item['state']]:'';
            $item['startDate'] = date('Y-m-d', strtotime($item['startDate']));
            $item['endDate'] = date('Y-m-d', strtotime($item['endDate']));
            $merber = M('member')->where(['uid' => $item['mid']])->find();
            $item['m_nickname'] = $merber['nickname']?$merber['nickname']:'无';
            if($item['state'] == 2){
                $item['operate'] = '<div onclick="dealWadan('.$item['id'].')">处理</div>';
            }else{
                $item['operate'] = "";
            }
        }
//        var_dump($ss);exit();
        $aa = $goods->getLastSql();

        $this->assign('alldata',$data);
        $this->assign('start_time',$time1);
        $this->assign('end_time',$time2);
        $this->assign('list', $ss);
        $this->assign('page',$p->show());
        $this->assign('state', I('get.state'));
        $this->assign('yes',date('Y-m-d', strtotime("-1days")));
        $this->assign('today',date('Y-m-d'));
        $this->assign('ming',date('Y-m-d', strtotime("+1days")));
        $this->display();
    }

    public function dealWandan(){

        $id = $_GET['id'];
        if(!$id) $this->ajaxReturn(['code' => -1, 'msg' =>'id不能为空']);
        $goods = M('zs_goods')->where(['id' => $id])->find();
        if(!isset($goods['id'])) $this->ajaxReturn(['code' => -1, 'msg' =>'未找到该商品']);
        if($goods['state'] == 3) $this->ajaxReturn(['code' => -1, 'msg' =>'改商品已处理']);
        $flag = M('zs_goods')->where(['id' => $id])->save(['state' =>3]);
        if(!$flag) $this->ajaxReturn(['code' => -1, 'msg' =>'操作失败']);
        $this->ajaxReturn(['code' => 1, 'msg' =>'操作成功']);
    }


    public function sellerlistdata(){

        import('ORG.Util.Page');// 导入分页类

        $model = new Model();
//        $zs_order_pay = M('zs_order_pay');
        $goods = $model->table('__ZS_SELLER__ as u');
        $seller_title = I('seller_title');
        $time1 = I('start_time');
        $time2 = I('end_time');
        $where2 = [];
        if ($time1 && $time2) {
            $where2 = ['endDate'=>['between', [$time1, $time2]]];
        }/*else{
            $where2 = ['u.endDate'=>['egt',$today]];
        }*/

        if($seller_title){
            $where2 = array_merge($where2,['seller_title'=>$seller_title]);
        }

        $user = session('user_auth');
        $where2 = array_merge($where2, isManager($user['group_id'], '', $user['uid']));

        $p = $this->getpage( $goods ,$where2,20);



        $list =  $goods ->field('*')
//            ->alias('u')
            ->where($where2)
            ->order('id asc')
            ->select();
        foreach($list as &$item){
            //订单数量
            $where = ['shopId' => $item['shopId']];
            $flag = M('zs_order_pay')->field('count(*) as order_num,
            sum(actualCosPrice) as actualCosPrice_total,
            sum(estimateCosPrice) as estimateCosPrice_total')->where($where)->find();
            $item['order_num'] = $flag['order_num']?$flag['order_num']:0;
            $item['actualCosPrice_total'] = $flag['actualCosPrice_total']?$flag['actualCosPrice_total']:0;
            $item['estimateCosPrice_total'] = $flag['estimateCosPrice_total']?$flag['estimateCosPrice_total']:0;
            $activity = M('zs_activity')->where(['taobao_act_id' => $item['taobao_act_id']])->find();
            $item['start_time'] = $activity['start_time'];
            $item['end_time'] = $activity['end_time'];
            $merber = M('member')->where(['uid' => $item['mid']])->find();
            $item['m_nickname'] = $merber['nickname']?$merber['nickname']:'无';
        }

//        $this->ajaxReturn($list);


        $this->assign('start_time',$time1);
        $this->assign('end_time',$time2);
        $this->assign('seller_title',$seller_title);
        $this->assign('list', $list);
        $this->assign('page',$p->show());
        $this->assign('state', I('get.state'));
        $this->assign('yes',date('Y-m-d', strtotime("-1days")));
        $this->assign('today',date('Y-m-d'));
        $this->assign('ming',date('Y-m-d', strtotime("+1days")));
        $this->display();
    }

    public function token(){

        if(IS_POST){
            $content = I('post.content');
            var_dump($content);
            $flag =  M('zs_jd_cookier')->where(['id' => 1])->save([
                'cookier_value' => $content,
                'update_time' => date('Y-m-d H:i:s'),
                'state' => 1,
                'count' => 0
            ]);
            if($flag === false)  $this->error('操作失败');
            $this->success('操作成功');

        }else{
            $data = M('zs_jd_cookier')->where(['id' => 1])->find();
            $this->assign('data', $data);
            $this->display();
        }
    }

}